<template>
    <div class="header-user">
        <div class="user-name" @click="isShow = !isShow">
            <a>欢迎{{userName}}同学<i class="iconfont icon-xiangxia"></i></a>
        </div>


        <div class="user-box-wrap" v-if="isShow" @click="isShow = !isShow">
            <div class="user-shadow"></div>
            <div class="user-box">
                <router-link to="/user">个人中心</router-link>
                <router-link to="" @click.native="loginOut">退出登录</router-link>
            </div>
        </div>

    </div>
</template>

<script>
    import { ref } from 'vue';
    export default {
        name: "HeaderUser",
        props: {
            userName: String
        },
        setup(props, context) {
            let isShow = ref(false);

            const loginOut = () => {
                context.emit('loginOut')
            }

            return {
                isShow,
                loginOut
            }
        }
    }
</script>

<style lang="scss" scoped>
.header-user {
    padding: 0 20px;
    cursor: pointer;

    .user-name {
        a {

            i {
                font-size: 10px
            }
        }
    }

    .user-shadow {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
    }

    .user-box {
        width: 100px;
        height: 70px;
        border: 1px solid #404040;
        border-radius: 5px;
        position: absolute;
        top: 45px;
        right: 50px;
        text-align: center;
        padding: 5px 0;
        background: white;
        z-index: 2;

        a {
            display: block;
            padding: 5px;

            &:hover {
                background-color: #e8f4ff;
                color: #46a6ff;
            }
        }
    }

}
</style>